<template>
  <div>
    <div class="hot">
      <header>热门城市</header>
      <ul v-if="hotlist">
        <li v-for="item in hotlist.cities" :key="item.cityId">
          {{ item.name }}
        </li>
      </ul>
    </div>

    <div v-for="item in citylist" :key="item.prefix" class="city">
      <header>{{ item.prefix | toup }}</header>
      <ul>
        <li v-for="value in item.cities" :key="value.cityId">
          {{ value.name }}
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { citiesApi } from "../utils/api";

export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      const res = await citiesApi();
      if (res.status == 0) {
        this.list = res.result;
      }
    },
  },
  computed: {
    hotlist() {
      return this.list[0];
    },
    citylist() {
      return this.list.slice(1);
    },
  },
  filters: {
    toup(val) {
      return val.toUpperCase();
    },
  },
};
</script>

<style lang="less" scoped>
.hot {
  header {
    font-size: 15px;
    background-color: #ebebeb;
    padding-left: 15px;
    line-height: 30px;
    color: #333;
  }
  ul {
    overflow: hidden;
    padding-bottom: 10px;
  }
  li {
    float: left;
    background: #fff;
    width: 95px;
    height: 33px;
    margin-top: 15px;
    margin-left: 4%;
    padding: 0 4px;
    border: 1px solid #e6e6e6;
    border-radius: 3px;
    line-height: 33px;
    text-align: center;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    color: #333;
  }
}
.city {
  header {
    padding-left: 25px;
    line-height: 30px;
    background-color: #ebebeb;
    font-size: 15px;
    color: #333;
  }
  li {
    height: 44px;
    line-height: 44px;
    margin-left: 15px;
    border-bottom: 1px solid #c8c7cc;
    font-size: 15px;
    color: #333;
    width: 90%;
  }
}
</style>
